<div id="username-password">
<fieldset>
<legend>Change Password</legend>
<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/

include_once '../includes/models/Account.php';
include_once '../includes/models/Auth.php';
include_once 'includes/forms/RegisterForm2.php';

$form2 = new RegisterForm2();
$account = new Account();
$authenticate = new Auth();

if (isset($_POST['accOldPassword']))
{
	if ($form2->isValid($_POST))
	{
		$dataForm2 = $_POST;
		$oldInfo = $account->get($authenticate->getIdentity());
		if (md5($dataForm2['accOldPassword']) == $oldInfo['accPassword'])	//check old password is right
		{
			$dataForm2['accPassword'] = md5($dataForm2['accPassword']);
			unset($dataForm2['button']);
			unset($dataForm2['accOldPassword']);
			unset($dataForm2['accPassword_check']);
			$account->edit($dataForm2,$authenticate->getIdentity());
			echo '<div class="success">Password changed.</div>';
		}
		else 
		{
			echo '<div class="errors">Wrong password.</div>';
		}
	}
}
echo $form2->render();
?>
</fieldset>
</div>